package main

import (
	"context"
	"fmt"
	"gitee.com/jinmingzhi/eth-learn/pkg/ethtool"
	"math/big"
)

var url = "http://127.0.0.1:8545"

func main() {
	client, err := ethtool.Dial(url)
	assert(err)
	ctx := context.Background()
	addresses, err := client.EthAccounts(ctx)
	assert(err)
	balance, err := client.EthGetBalance(ctx, addresses[2], "latest")
	assert(err)
	fmt.Printf("address: %s, balance@latest: %f\n", addresses[2].Hex(), ethtool.FromWei(balance, ethtool.Ether))

	balance, err = client.EthGetBalance(ctx, addresses[2], "earliest")
	assert(err)
	fmt.Printf("address: %s, balance@earliest: %f\n", addresses[2].Hex(), ethtool.FromWei(balance, ethtool.Ether))

	fmt.Println(ethtool.ToWei(big.NewFloat(3.44), ethtool.Kwei))
	fmt.Println(ethtool.ToWei(big.NewFloat(20), ethtool.Gwei))
	fmt.Println(ethtool.FromWei(big.NewInt(5200), ethtool.Kwei))

}

func assert(err error) {
	if err != nil {
		panic(err)
	}
}
